<script  lang="ts" setup>

import { ref} from "vue";
import {useRouter} from "vue-router";

// 表格数据相关
const dataList = ref<API.Picture[]>([]);
const loading = ref(true);

const router = useRouter()

interface Props {
  dataList?: API.PictureVO[]
  loading?: boolean
  pagination?: null
}

const props = withDefaults(defineProps<Props>(), {
  dataList: () => [],
  loading: false,
  pagination: null
})

const doClickPiture = (picture: API.PictureVO) => {
  router.push({
    path: `/picture/${picture.id}`
  })
}
</script>

<template>
  <div class="picture-home-container">
    <!-- 图片列表 -->
    <div class="picture-gallery">
      <a-list
          :grid="{ gutter: 24, xs: 1, sm: 2, md: 3, lg: 4, xl: 4, xxl: 5 }"
          :data-source="props.dataList"
          :pagination="props.pagination"
      >
        <template #renderItem="{ item: picture }">
          <a-list-item>
            <div class="picture-card-wrapper">
              <div class="picture-card" @click="doClickPiture(picture)">
                <div class="card-hover">
                  <span class="view-text">查看详情</span>
                </div>
                <img
                    :src="picture.url"
                    :alt="picture.name"
                    class="picture-image"
                />
                <div class="card-content">
                  <h3 class="picture-title">{{ picture.name }}</h3>
                  <div class="picture-meta">
                    <div class="meta-item">
                      <span class="meta-icon">📅</span>
                      {{ new Date(picture.createTime).toLocaleDateString() }}
                    </div>
                    <div class="meta-item">
                      <span class="meta-icon">👁️</span>
                      {{ (picture.viewCount || 0).toLocaleString() }}
                    </div>
                  </div>
                  <div class="picture-tags">
                    <span class="category-tag">{{ picture.category || '默认' }}</span>
                    <span
                        v-for="tag in picture.tags"
                        :key="tag"
                        class="tag"
                    >
                      {{ tag }}
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </a-list-item>
        </template>

        <!-- 加载状态 -->
        <template #empty>
          <div class="loading-state">
            <div class="loading-wave">
              <div class="wave"></div>
              <div class="wave"></div>
              <div class="wave"></div>
            </div>
            <span class="loading-text">正在加载创意灵感...</span>
          </div>
        </template>
      </a-list>
    </div>
  </div>
</template>

<style scoped lang="less">
@primary-color: #6366f1;
@bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);

.picture-home-container {
  padding: 0 2rem;
  background: @bg-gradient;
  min-height: 100vh;
}

.hero-section {
  position: relative;
  padding: 4rem 0;
  margin-bottom: 2rem;
  overflow: hidden;

  .search-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
  }

  .search-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 150%;
    background: radial-gradient(circle, rgba(99,102,241,0.2) 0%, transparent 60%);
    transform: translate(-50%, -50%);
  }

  .hero-title {
    color: #e2e8f0;
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 2rem;
    text-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }
}

.neo-search {
  :deep(.ant-input-search-button) {
    background: linear-gradient(45deg, @primary-color, #8b5cf6);
    border: none;
    height: 48px;
    padding: 0 2rem;
    font-weight: 500;
    transition: all 0.3s ease;

    &:hover {
      transform: scale(1.02);
      box-shadow: 0 4px 15px rgba(@primary-color, 0.3);
    }
  }

  :deep(.ant-input) {
    height: 48px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(99,102,241,0.3);
    color: #e2e8f0;
    border-radius: 12px;
    padding-left: 3rem;

    &:focus {
      box-shadow: 0 0 0 2px rgba(@primary-color, 0.2);
    }
  }

  .search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;

    .icon {
      width: 24px;
      height: 24px;
      fill: #818cf8;
    }
  }
}

.category-filter {
  margin: 2rem 0;
  overflow-x: auto;

  .filter-scroll {
    display: flex;
    gap: 1rem;
    padding-bottom: 1rem;
  }

  .category-item {
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.6);
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    white-space: nowrap;

    &.active {
      background: @primary-color;
      color: white;
      font-weight: 500;

      .active-bar {
        width: 100%;
      }
    }

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(@primary-color, 0.2);
    }
  }
}

.tag-filter {
  margin-bottom: 2rem;
  overflow-x: auto;

  .tag-scroll {
    display: flex;
    gap: 0.8rem;
    padding-bottom: 1rem;
  }

  .tag-item {
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    background: rgba(99,102,241,0.15);
    color: #818cf8;
    cursor: pointer;
    transition: all 0.3s ease;

    &.active {
      background: @primary-color;
      color: white;
      transform: scale(1.05);
    }

    &:hover {
      background: rgba(99,102,241,0.3);
    }
  }
}

.picture-gallery {
  padding-bottom: 4rem;

  .picture-card-wrapper {
    padding: 8px;
  }

  .picture-card {
    background: rgba(15, 23, 42, 0.8);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;

    &:hover {
      transform: translateY(-8px);
      box-shadow: 0 12px 24px rgba(0,0,0,0.3);

      .card-hover {
        opacity: 1;
      }

      .picture-image {
        transform: scale(1.05);
      }
    }

    .card-hover {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.5);
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 0.3s ease;

      .view-text {
        color: white;
        font-size: 1.2rem;
        text-shadow: 0 2px 4px rgba(0,0,0,0.3);
      }
    }

    .picture-image {
      width: 100%;
      height: 240px;
      object-fit: cover;
      transition: transform 0.3s ease;
    }

    .card-content {
      padding: 1.2rem;

      .picture-title {
        color: #e2e8f0;
        margin-bottom: 0.8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .picture-meta {
        display: flex;
        gap: 1rem;
        margin-bottom: 1rem;
        color: #94a3b8;
        font-size: 0.9rem;

        .meta-icon {
          margin-right: 4px;
        }
      }

      .picture-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;

        .category-tag {
          background: rgba(@primary-color, 0.15);
          color: @primary-color;
          padding: 4px 8px;
          border-radius: 4px;
        }

        .tag {
          background: rgba(255,255,255,0.1);
          color: #cbd5e1;
          padding: 4px 8px;
          border-radius: 4px;
          font-size: 0.9rem;
        }
      }
    }
  }
}

.loading-state {
  padding: 4rem 0;
  text-align: center;

  .loading-wave {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 1rem;

    .wave {
      width: 4px;
      height: 24px;
      background: @primary-color;
      animation: wave 1s ease-in-out infinite;

      &:nth-child(2) { animation-delay: 0.2s; }
      &:nth-child(3) { animation-delay: 0.4s; }
    }
  }

  .loading-text {
    color: #94a3b8;
  }
}

@keyframes wave {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.5); }
}

@media (max-width: 768px) {
  .hero-section {
    padding: 2rem 0;

    .hero-title {
      font-size: 1.8rem;
    }
  }

  .category-filter .category-item {
    padding: 0.6rem 1rem;
  }

  .picture-card .picture-image {
    height: 180px;
  }
}
</style>
